<template>
    <nly-content-wrapper class="content-warpper-2" :style="addBtnShow?{'border':'none'}:{}">
        <div class="content-header-2">
            <!--按钮-->
            <div class="btn-wrapper clearfix" :style="addBtnShow?{'border':'none','padding-top':'0','height':'52px' }:{}">
                <a-row class="text-center clearfix">
                    <a-col v-if="addBtnShow" style="text-align:left;line-height:52px;">
                        <a-button @click="AddItem" class="margin-left-10 margin-right-10" type="primary" ghost>
                            <a-icon type="file-add" theme="filled" />新增
                        </a-button>
                        <a-button @click="EditItem()" class="margin-right-10" type="primary" ghost>
                            <a-icon type="edit" theme="filled" />编辑
                        </a-button>
                        <a-button @click="Disable" class="margin-right-10" type="primary" ghost>
                            <a-icon type="delete" theme="filled" />删除
                        </a-button>
                        <!-- <a-button @click="onShowSerch" class="margin-right-10">
                            <a-icon type="file-search" />查询
                        </a-button> -->
                        <!-- <a-button @click="showMySet" class="margin-right-10">
                            <a-icon type="setting" />自定义列
                        </a-button> -->
                    </a-col>
                    <a-col v-else :xs="24" :sm="24" :md="24" :lg="16" :xl="12">
                        <a-col :xs="btnGrid.xs" :sm="btnGrid.sm" :md="btnGrid.md" :lg="btnGrid.lg" :xl="btnGrid.xl">
                            <div class="btns" @click="AddItem">
                                <a-icon class="btns-icon" type="file-add" />
                                <div class="btns-text">新增</div>
                            </div>
                        </a-col>
                        <a-col :xs="btnGrid.xs" :sm="btnGrid.sm" :md="btnGrid.md" :lg="btnGrid.lg" :xl="btnGrid.xl" v-if="editBtnShow">
                            <div class="btns" @click="EditItem()">
                                <a-icon class="btns-icon" type="edit" />
                                <div class="btns-text">编辑</div>
                            </div>
                        </a-col>
                        <a-col :xs="btnGrid.xs" :sm="btnGrid.sm" :md="btnGrid.md" :lg="btnGrid.lg" :xl="btnGrid.xl" v-if="disableBtnShow">
                            <div style="position:relative">
                                <div class="btns" @click="Disable">
                                    <a-icon class="btns-icon" type="delete" />
                                    <div class="btns-text">删除</div>
                                </div>
                                <div style="position:absolute;width:2px;height:36px;border-radius:6px;background:#ccc;top:0px;right:0px;"></div>
                            </div>
                        </a-col>
                        <a-col :xs="btnGrid.xs" :sm="btnGrid.sm" :md="btnGrid.md" :lg="btnGrid.lg" :xl="btnGrid.xl">
                            <div class="btns" @click="showMySet">
                                <a-icon class="btns-icon" type="setting" />
                                <div class="btns-text">自定义列</div>
                            </div>
                        </a-col>
                        <a-col :xs="btnGrid.xs" :sm="btnGrid.sm" :md="btnGrid.md" :lg="btnGrid.lg" :xl="btnGrid.xl">
                            <div class="btns" @click="GetCustomizeList">
                                <a-icon class="btns-icon" type="sync" />
                                <div class="btns-text">同步设置</div>
                            </div>
                        </a-col>
                    </a-col>
                    
                </a-row>
            </div>
            <!-- 查询方案 -->
            <a-col :span="24" v-if="!addBtnShow">
                <div class="search-btn-box-gw">
                    <div class="item-small" ref="planLi">
                        <ul>
                            <li class="item-plan" :class="planActive == 0?'active':''" @click="onUserSearchChange()">所有</li>
                            <li class="item-plan" :title="item.searchName" :class="item.id == planActive?'active':''" v-for="(item,index) in userSearchList" :key="index" @click="onUserSearchChange(item.id)">{{item.searchName}}</li>
                            <li class="item-plan" @click="onShowSerch">
                                <!-- <a-icon class="icon-searh-btn" type="file-search" /> 查询 -->
                                自定查询
                                <a-icon class="icon-searh-btn" type="search" />
                            </li>
                        </ul>
                    </div>
                    <div class="item-small-down" v-if="showDownPlan" @click="showDownPlanFun">
                        <a-icon v-if="iconDirection" type="down" />
                        <a-icon v-else type="up" />
                    </div>
                </div>
            </a-col>
            <!-- 查询方案结束 -->

            <!-- <nly-row class="col-12">
                <nly-row class="col-12">
                    <fixed-condition :conditions="conditions" :FixedConditionKeys="FixedConditionKeys" :show="show" :userSearchList="userSearchList" :userSearchSelect="userSearchSelect" :onUserSearchChange="onUserSearchChange" :onUserSearchDelete="onUserSearchDelete" rightStyle="width:150px;" rangDaterightStyle="min-width:150px;max-width:calc(410px + 0.25rem);"></fixed-condition>
                    <div class="mb-1">
                        <nly-button @click="showFunction" variant="info" button-class="mr-2"><i :class="show ? 'fas fa-angle-down mr-1' : 'fas fa-angle-up mr-1'" />{{ show ? "折 叠" : "展 开" }}
                        </nly-button>
                        <nly-button variant="info" @click="onSerch" button-class="mr-2" :disabled="loading">查询</nly-button>
                        <nly-button variant="info" button-class="mr-2" @click="reset" :disabled="loading">重置</nly-button>

                        <nly-button variant="info" @click="showUsModal" button-class="mr-2">保存常用查询</nly-button>

                    </div>
                </nly-row>
            </nly-row>
            <dynamic-condition :conditions="conditions" :FixedConditionKeys="FixedConditionKeys" :show="show" :userSearchList="userSearchList" :userSearchSelect="userSearchSelect" :onUserSearchChange="onUserSearchChange" :onUserSearchDelete="onUserSearchDelete" rightStyle="width:150px;" rangDaterightStyle="min-width:150px;max-width:calc(410px + 0.25rem);"></dynamic-condition> -->

            <!-- 自定义列 -->
            <a-drawer class="mySet" title="自定义列" width="520" height="300" @close="onMySetClose" :visible="mySetVisible">
                <a-checkbox-group v-model="mySetcheckedListLocal" :options="mySetplainOptions" @change="onMySetChange" />
                <nly-col xs="12" sm="12" class="form-inline align-self-start mt-3" style>
                    <nly-button-group>
                        <nly-button variant="danger" @click="onMySetClose" button-class="mr-2">关闭</nly-button>
                        <nly-button variant="info" button-class="mr-2" @click="saveMyShow">确定</nly-button>
                    </nly-button-group>
                </nly-col>
            </a-drawer>
            <nly-container fluid></nly-container>
        </div>
        <!-- 功能操作 -->
        <!-- <div>
            <a-button type="primary" class="crm-btn" @click="EditItem()" v-if="editBtnShow">编辑</a-button>
            <a-button type="primary" class="crm-btn" @click="Disable" v-if="disableBtnShow">删除</a-button>
            <a-button type="primary" class="crm-btn" @click="AddItem" v-if="addBtnShow">新增</a-button>
            <i class="fa fa-fw fa-cog fieldSet " @click="showMySet"></i>
        </div> -->
        <nly-content>
            <!-- 列表 -->
            <a-table id="touch_tb" :columns="columns" :rowClassName="rowClassName" :data-source="data" :scroll="{ x: 500, y: 500 }" bordered :loading="loading" :pagination="pagination" @change="onTableChange" :row-selection="{selectedRowKeys: selectedKeys, onChange: selection}">
                <a slot="crmName" slot-scope="text, record" @click="goToDetail(record,'touch')" class="goToDetail">
                    {{record.crmName}}
                </a>
                <a slot="remarks" slot-scope="text, record" @click="goToDetail(record,'touch')" class="goToDetail" style="white-space:break-spaces;">
                    {{text}}
                </a>
                <div slot="isMain" slot-scope="text">
                    {{text ? "是":"否"}}
                </div>
                <div slot="photograph" slot-scope="text">
                    <a :href="text" target="_blank"><img :src="text" style="max-height:50px;max-width:50px;margin-left:10px;"></a>
                </div>
            </a-table>
            <!-- modal 弹窗  -->
            <drag-modal :title="formPostData.id ? '编辑拜访记录' : '新增拜访记录'" :visible="ModalVisible" @ok="onSubmit" @cancel="hideModal" class="add-or-edit-modal">
                <div class="min-box">
                    <nly-row class="form-inline zidongshifang">
                        <nly-col v-if="!addBtnShow" sm="12" lg="12">
                            <form-select title="客户名称" labelStyle="" rightClass="myRightClass" class="ml-1 mb-2" :required="true" :error="errors['formPostData.crmId']" :showSearch="true" :dataList="customerSelect" :handleSearch="delaySearch" :filterOption="false" v-model="formPostData.crmId" @input="inputLog" :valueTitle.sync="formPostData.crmName" :disabled="customerId">
                            </form-select>
                        </nly-col>
                        <nly-col sm="12" lg="12">
                            <form-select title="拜访人" labelStyle="" rightClass="myRightClass" class="ml-1 mb-2" :error="errors['formPostData.linkManId']" :required="true" :showSearch="true" :handleSearch="delaySearchLinkMain" :filterOption="false" v-model="formPostData.linkManId" :valueTitle.sync="formPostData.linkManName" :dataList="LinkManList">
                            </form-select>
                        </nly-col>
                        <nly-col sm="12" lg="12">
                            <form-input title="部门" labelStyle="" rightClass="myRightClass" class="ml-1 mb-2" :value="SelectedLinkMan.dept" :readonly="true">
                            </form-input>
                        </nly-col>
                        <nly-col sm="12" lg="12">
                            <form-input title="职务" labelStyle="" rightClass="myRightClass" class="ml-1 mb-2" :value="SelectedLinkMan.position" :readonly="true">
                            </form-input>
                        </nly-col>
                        <nly-col sm="12" lg="12">
                            <form-input title="手机" labelStyle="" rightClass="myRightClass" class="ml-1 mb-2" :value="SelectedLinkMan.mobile" :readonly="true">
                            </form-input>
                        </nly-col>
                        <nly-col sm="12" lg="12">
                            <form-input title="办公电话" labelStyle="" rightClass="myRightClass" class="ml-1 mb-2" :value="SelectedLinkMan.officePhone" :readonly="true">
                            </form-input>
                        </nly-col>
                    </nly-row>

                    <!-- 动态 表单  -->
                    <dynamic-form :formPostData="formPostData" :initFormData="initFormData" :errors="formErrors" :isOk="isFromShow"></dynamic-form>

                    <a-divider v-if="formPostData.id" orientation="left" style="margin:0px 0px 1rem 0px;">其他信息</a-divider>
                    <a-row v-if="formPostData.id" class="form-inline not-border-form">
                        <a-col :span="24">
                            <form-input title="创建人" labelStyle="" rightClass="myRightClass" :value="formPostData.createUserName" :readoa="true"></form-input>
                        </a-col>
                        <a-col :span="24">
                            <form-input title="创建时间" labelStyle="" rightClass="myRightClass" :value="formPostData.createDate" :readoa="true"></form-input>
                        </a-col>
                        <a-col :span="24">
                            <form-input title="修改人" labelStyle="" rightClass="myRightClass" :value="formPostData.updateUserName" :readoa="true"></form-input>
                        </a-col>
                        <a-col :span="24">
                            <form-input title="修改时间" labelStyle="" rightClass="myRightClass" :value="formPostData.updateDate" :readoa="true"></form-input>
                        </a-col>
                    </a-row>
                </div>
                <template slot="footer">
                    <div>
                        <a-button type="primary" @click="onSubmit">确认</a-button>
                        <a-button @click="hideModal" class="margin-left-10">关闭</a-button>
                    </div>
                </template>
            </drag-modal>
            <!-- 常用查询名称编辑框 -->
            <a-modal title="保存常用查询" :visible="UsVisible" @ok="UserSearchSave" @cancel="hideUsModal">
                <nly-row class="form-inline">
                    <form-input title="名称" rightStyle="flex-grow:1;" class="ml-1 mb-1" style="flex:0.8;" :error="myUsErrors['userSearchEditItem.searchName']" :required="true" v-model="userSearchEditItem.searchName"></form-input>
                </nly-row>
            </a-modal>

            <!-- 查询方案弹窗 -->
            <a-modal class="search-wrapper-box-crm" :visible="visibleSearchPlan" title="查询" @cancel="cancel" width="1000px">
                <div class="content-box">
                    <div class="left-box">
                        <a-row class="btn-wrapper">
                            <a-col :class="planActive != 0?'':'btns-disable'" :span="6">
                                <div class="btns" @click="planActive != 0?UserSearchSave():''">
                                    <a-icon class="btns-icon" type="save" />
                                    <div class="btns-text">保存</div>
                                </div>
                            </a-col>
                            <a-col :span="6">
                                <div class="btns" @click="showUsModal(2)">
                                    <a-icon class="btns-icon" type="save" />
                                    <div class="btns-text">另存</div>
                                </div>
                            </a-col>
                            <a-col :class="planActive != 0?'':'btns-disable'" :span="6">
                                <div class="btns" @click="planActive != 0?showUsModal(1):''">
                                    <a-icon class="btns-icon" type="edit" />
                                    <div class="btns-text">修改</div>
                                </div>
                            </a-col>
                            <a-col :class="planActive != 0?'':'btns-disable'" :span="6">
                                <div class="btns" @click="planActive != 0?onUserSearchDelete({key:planActive}):''">
                                    <a-icon class="btns-icon" type="delete" />
                                    <div class="btns-text">删除</div>
                                </div>
                            </a-col>
                        </a-row>
                        <div class="plan-list">
                            <ul>
                                <li :class="planActive == 0?'active':''" @click="onUserSearchChange()">所有</li>
                                <li v-for="(item,index) in userSearchList" :key="index" :class="item.id == planActive?'active':''" @click="onUserSearchChange(item.id)">{{item.searchName}}</li>
                            </ul>
                        </div>
                    </div>
                    <div class="right-box">
                        <a-tabs default-activeKey="1" @change="callback">
                            <a-tab-pane key="1" tab="查询条件">
                                <dynamic-condition v-if="visibleSearchPlan" :checkable="true" :conditions="conditions" :show="true" :userSearchList="userSearchList" :userSearchSelect="userSearchSelect" :onUserSearchChange="onUserSearchChange" :onUserSearchDelete="onUserSearchDelete" rightStyle="width:150px;" rangDaterightStyle="min-width:150px;max-width:calc(410px + 0.25rem);"></dynamic-condition>
                            </a-tab-pane>
                        </a-tabs>
                    </div>
                </div>
                <template slot="footer">
                    <div>
                        <!-- <div style="float:left">
                            <a-checkbox :checked="planActive == defaultPlanActive?true:false" @change="inPagePlanSave">
                                下次以此方案进入
                            </a-checkbox>
                        </div> -->
                        <a-button type="primary" @click="onSerch">查询</a-button>
                        <a-button @click="cancel" class="margin-left-10">取消</a-button>
                    </div>
                </template>
                <a-modal :title="nowPlanType==1?'保存为另一个方案':'修改方案标题'" :visible="saveASVisible" width="400px" centered @cancel="saveAsPlanClose">
                    <a-input v-model="saveAsName" placeholder="请输入查询方案名称"></a-input>
                    <template slot="footer">
                        <div>
                            <a-button type="primary" @click="saveAsPlanSubmit(1)">确定</a-button>
                            <a-button @click="saveAsPlanClose" class="margin-left-10">取消</a-button>
                        </div>
                    </template>
                </a-modal>
            </a-modal>
            <drawerCrm ref="drawerCrm" :drawerVisible.sync="drawerVisible" :routeUrl="routeUrl" :title="drawerTitle" :dataItem="dataItem"></drawerCrm>
        </nly-content>
    </nly-content-wrapper>
</template>

<script>
import { mapState } from "vuex";
import { listToMap } from "@/utils/tool/map";
import { deepCopy } from "@/utils/tool/object";
import { Controlwidth } from "@/utils/antTableComponents";
import getDate from "@/utils/tool/date";

import { PageList, Save as SaveTouch, disable, enable, detail, historyList } from "@/api/crm/touch";
import { List as ListLinkMan } from "@/api/crm/linkMan";
import { clearValue, clearKeys } from "@/utils/tool/object";
import { officeUserListToTree, searchInTreeData } from "@/utils/tree";
import { initValidator, checkAll } from "@/utils/validator/validator";
import { listToSelectOptionData, IdFieldToNameField } from "@/utils/customize"

import { pageForSelect } from "@/api/crm/customer";

import dynamicList from "@/mixins/dynamicList";

import MiddleUtils from '@/utils/middle-utils'

let searchTimeout;

export default {
    mixins: [dynamicList],
    props: {
        activeKey: {
            type: String,
            default: ''
        }
    },
    data () {
        return {
            //----------↓样式----------
            btnGrid: {
                xs: 2,
                sm: 2,
                md: 2,
                lg: 2,
                xl: 2
            },
            //----------↑样式----------

            //gw 2021年8月16日11:04:08
            visibleSearchPlan: false,
            //gw 2021年8月16日11:04:16
            searchType: 4,       //
            source: "touch",
            crmType: '0,1,2',
            FixedConditionKeys: ["remarks", "crmName"],  //固定的搜索条件的Key
            fiexdColumnInTbCodes: ["remarks"],
            customRenderCode: ["crmName", "remarks", "isMain", "photograph"], //table 使用插槽的列
            FixedFormKeys: ["linkManId", ""],  //固定表单keys
            LinkManDataMap: new Map(),            //拜访记录 数据Map
            LinkManList: [],               //拜访记录 下拉集合


            //下拉搜索 客户条件
            selectPostData: {
                page: {
                    current: 1,
                    size: 1000
                },
                keyWord: '',
            },
            customerSelect: [],              //下拉搜索 客户
            route: this.$route.path,

            drawerVisible: false,//客户详情抽屉
            routeUrl: '',
            drawerTitle: '',
            dataItem: [],
            crmNameValue: null,
            rowClassName: (record, index) => {
                if (record.clickActive) {
                    return 'click-table-active'
                }
            },
        }
    },
    components: {
        drawerCrm: () => import('@/components/Crm/drawer')
    },
    beforeCreate: function () {
        // this.$options.components.drawerCrm = require('@/components/Crm/drawer').default;
    },
    created () {
        const { formRules } = this;
        formRules["formPostData.crmId"] = { test: "required" };
    },
    watch: {
        customerId: function (n, o) {
            console.log("watch_touch_customerId", n, o)
            const { basePostData } = this;
            basePostData.customerIds = n;
            this.resetConditions();
            this.selectedKeys = [];
        },
        "activeKey": function (n, o) {
            console.log("watch_touch_activeKey", n, o)
            if (n == 'touch') {
                let array = [];
                this.columns.forEach(item => {
                    if (item.dataIndex) {
                        array.push(item.dataIndex)
                    }
                });
                if (!array.includes('type')) {
                    this.columns.push({
                        title: '拜访方式',
                        dataIndex: 'type',
                        align: "left",
                        width: 140,
                        onLocked: true,
                        customRender: (text, record, inded) => {
                            return text == 1 ? '会话沟通' : text == 2 ? '外勤签到' : '';
                        }
                    })
                }
            }
            if ("touch" == n) {
                this.PageList();
                //重新加载拜访记录
                this.ListLinkMan();
            }
        },
        'formPostData.crmId' (val) {

            console.log('选择的客户名称_______', this.formPostData, val);
            this.ListLinkMan();
        },
        $route: {
            handler (nv, ov) {
                //离开路由关闭 右侧详情抽屉
                this.drawerVisible = false;
            },
            deep: true
        },
    },
    activated () {
        this.ListLinkMan();
    },
    mounted () {
        MiddleUtils.$on('syncList', (value) => {
            if(this.$route.path == '/crm/touch/list'){
                console.log("刷新syncList---联系记录");
                this.PageList();
            }
        })
    },
    updated () {
        Controlwidth("touch_tb", 50);
    },
    computed: {
        SelectedLinkMan: function () {
            let { formPostData, LinkManDataMap } = this;
            if (formPostData.linkManId) {
                return LinkManDataMap.get(formPostData.linkManId) || {};
            }
            return {};
        },
        //是否显示 新增按钮 
        addBtnShow: function () {
            const { customerId, customer, permissions, userInfo } = this;
            const { crmType } = customer;
            let isShow = false;
            if (
                customerId
                && (permissions.includes("crm:touch:add")
                    || (crmType == 0 && permissions.includes("crm:clue:touch:add"))
                    || (crmType == 1 && permissions.includes("crm:potential:touch:add"))
                    || (crmType == 2 && permissions.includes("crm:deals:touch:add"))
                )
            ) {
                isShow = true;
            }
            return isShow;
        },
        //是否显示 编辑按钮 
        editBtnShow: function () {
            const { customerId, customer, permissions, userInfo } = this;
            const { crmType } = customer;
            let isShow = false;
            if (
                permissions.includes("crm:touch:edit")
                || (crmType == 0 && permissions.includes("crm:clue:touch:edit"))
                || (crmType == 1 && permissions.includes("crm:potential:touch:edit"))
                || (crmType == 2 && permissions.includes("crm:deals:touch:edit"))
            ) {
                isShow = true;
            }
            return isShow;
        },
        //是否显示 删除按钮 
        disableBtnShow: function () {
            const { customerId, customer, permissions, userInfo } = this;
            const { crmType } = customer;
            let isShow = false;
            if (
                permissions.includes("crm:touch:disable")
                || (crmType == 0 && permissions.includes("crm:clue:touch:disable"))
                || (crmType == 1 && permissions.includes("crm:potential:touch:disable"))
                || (crmType == 2 && permissions.includes("crm:deals:touch:disable"))
            ) {
                isShow = true;
            }
            return isShow;
        },
    },
    methods: {
        inputLog (e) {
            console.log("from_select input:", e, JSON.stringify(this.formPostData))
        },
        //延迟 搜索
        delaySearch (value) {
            console.log("delaySearch...", value, searchTimeout);
            if (searchTimeout) {
                clearTimeout(searchTimeout);
                searchTimeout = null;
            }
            const go = () => { this.pageForSelect(value) }
            searchTimeout = setTimeout(go, 400);
        },
        delaySearchLinkMain (value) {
            let timeout = null;
            if (searchTimeout) {
                clearTimeout(searchTimeout);
                timeout = null;
            }
            const go = () => { this.ListLinkMan(value) }
            timeout = setTimeout(go, 400);
        },
        //下拉搜索 客户
        pageForSelect (keyWord) {
            const { selectPostData } = this;
            Object.assign(selectPostData, { keyWord });
            selectPostData.crmTypes = [1, 2];//潜在客户
            selectPostData.page.size = 200;
            pageForSelect(selectPostData).then(response => {
                if (response.code === 200) {
                    const { data } = response;
                    const { records } = data;
                    this.customerSelect = records;
                    console.log("搜索结果", records)
                }
            }).catch(error => { });
        },
        //跳转到 客户详情
        goToDetail (item, tabkey) {
            const { permissions } = this;
            if (!this.customerId && (permissions.includes("crm:potential:edit") || permissions.includes("crm:potential:edit") || permissions.includes("crm:deals:edit"))) {
                // this.$router.push(`/crm/customer/detail/${item.crmName}/${item.crmId}/${tabkey}`)
                this.drawerVisible = true;
                this.routeUrl = window.location.host + `/crm/customer/detail/${item.crmName}/${item.crmId}/${tabkey}`;
                this.drawerTitle = item.crmName;
                this.dataItem = item;
                this.$forceUpdate();
                //给点击的行一个颜色
                this.data.map(d => {
                    this.$set(d, 'clickActive', false)
                });
                this.$set(item, 'clickActive', true)
            }
        },
        //查询 当前客户的拜访记录
        ListLinkMan (value) {
            const { customerId, LinkManList, formPostData } = this;
            let postData = { customerId };
            //如果是编辑
            if (formPostData.id || formPostData.crmId) {
                postData.customerId = formPostData.crmId;
            }
            postData.size = 200;
            if (value) {
                postData.keyWord = value;
            }
            ListLinkMan(postData).then(response => {
                console.log("获取拜访记录列表", response);
                if (response.code === 200) {
                    let data = response.data.records;
                    let options = [];
                    let LinkManDataMap = new Map();
                    data.forEach(item => {
                        LinkManDataMap.set(item.id, item);
                    });
                    listToSelectOptionData(options, data, { label: "name", value: "id" });

                    console.log("touch_options", options)
                    Object.assign(this, {
                        LinkManList: options,
                        LinkManDataMap
                    })

                }
            }).catch(error => { });
        },
        //添加
        AddItem () {
            this.selectPostData.keyWord = '';
            this.pageForSelect();
            const { formErrors, customer, userInfo } = this;
            const { crmName, id } = customer;
            clearKeys(formErrors);
            //PC端的跟进方式 默认type=1（电话沟通）
            let formPostData = { type:1, crmName, crmId: id, salesManId: userInfo.id, salesManName: userInfo.name }
            //获取当前时间
            let now = getDate.getCurrentMoment();
            Object.assign(this, { formPostData })
            this.$set(this.formPostData, "contactDate", now.format("YYYY-MM-DD"));
            // this.$set(this.formPostData,"salesManId",userInfo.id);
            // this.$set(this.formPostData,"salesManName",userInfo.name);
            this.isFromShow = true;
            this.ModalVisible = true;

            console.log("AddItem_formErrors->", formErrors)
        },
        //编辑
        EditItem (id) {
            const { selectedKeys, editBtnShow } = this;
            if (!editBtnShow) {
                return false;
            }
            if (!id) {
                let isOk = this.checkSingleSelectKey();
                if (!isOk) {
                    return false;
                }
                id = selectedKeys[0];
            }
            this.selectPostData.keyWord = '';
            this.pageForSelect();
            //查询拜访记录
            detail({ id }).then(response => {
                console.log("获取拜访记录详情", response);
                if (response.code === 200) {
                    const { data } = response;
                    // delete data.createDate;
                    // delete data.updateDate;
                    delete data.status;
                    Object.assign(this, {
                        formPostData: data,
                    });
                    if (!this.customerId) {
                        this.ListLinkMan();
                    }
                    this.initCustomize();
                }
            }).catch(error => { });
            this.isFromShow = true;
            this.ModalVisible = true;
        },
        onSerch () {
            const { postData } = this;
            postData.page.current = 1;
            this.PageList();
            this.cancel();
        },
        // 获取列表
        PageList () {
            const { postData, onOffDefineFields, source, customerId, customer } = this;
            // Object.assign(postData,{ customerIds: this.customerId})
            console.log("拜访记录——搜索条件：", postData, onOffDefineFields, this.customerId);
            postData.dtos = onOffDefineFields;
            postData.type = source;   //查询共享模块
            if (customerId) {
                postData.crmType = customer.crmType;
            }else{
                postData.isGetSaleManId = true;
            }
            this.loading = true;
            PageList(postData).then(response => {
                this.loading = false;
                console.log("获取拜访记录列表", response);
                if (response.code === 200) {
                    const { data } = response;
                    const { records, total, current, size } = data;
                    //转换自定义数据数据
                    this.defineFieldsAddToData(records);

                    this.data = records;
                    console.log("转换后的数据：records", records);
                    Object.assign(this.pagination, {
                        total
                    });
                }
            }).catch(error => { });
        },
        //提交表单
        onSubmit () {
            const {
                crmType,
                formRules,
                formPostData,
                formErrors,
                onOffDefineFields,
                customerId
            } = this;
            console.log(`提交的数据formPostData：`, formPostData)
            //全部校验一次
            checkAll(this, formRules, formPostData, formErrors);
            if (Object.keys(formErrors).length > 0) {
                this.isFromShow = false;
                this.$nextTick(function () {
                    this.isFromShow = true;
                });
                return false;
            }
            //自定义字段 重组
            let defineFieldsSets = onOffDefineFields.filter(f => f.dataType == 2);
            let defineFields = {};
            //获取重组后的自定义集合
            this.getDefineFields(defineFields, formPostData, defineFieldsSets);
            Object.assign(formPostData, {
                defineFields: JSON.stringify(defineFields)
            });
            let _this = this;
            SaveTouch(formPostData).then(response => {
                console.log("SaveCustomer_response.code", response.code);
                if (response.code === 200) {
                    _this.$message.success("保存成功");
                    _this.hideModal();
                    if (_this.customerId) {
                        MiddleUtils.$emit('syncList');
                    }
                    _this.PageList();
                }
            })
        },
        //删除拜访记录
        Disable () {
            const { selectedKeys } = this;
            let isOk = this.checkSingleSelectKey(true);
            if (!isOk) {
                return false;
            }
            let _this = this;
            let ids = selectedKeys.join(",");
            this.$confirm({
                title: '确认',
                content: '您确定要删除该拜访记录吗？',
                onOk () {
                    disable({ ids })
                        .then(response => {
                            if (response.code === 200) {
                                _this.$message.success("删除成功");
                                _this.PageList();
                                _this.selectedKeys = [];
                            }
                        })
                },
                onCancel () { },
            });
        },
        //获取拜访记录修改历史
        getHostoryList () {
            this.loading = true;
            const { customerId } = this;
            let postData = {
                crmId: customerId
            }

        },
        //gw 2021年8月16日11:51:51
        cancel () {
            //置空临时查询条件
            // if (this.planActive == 0) {
            //     setTimeout(() => {
            //         this.onOffDefineFields.forEach(item => {
            //             item.value = '';
            //         });
            //     }, 200)
            // }
            this.visibleSearchPlan = false;
        },
        onShowSerch () {
            this.visibleSearchPlan = true;
        },
    },
};
</script>
<style lang="less" >
    .linkMan-des {
        .ant-descriptions-view {
            padding: 0 3rem !important;
        }
        .ant-descriptions-title {
            margin-bottom: 0px !important;
        }
    }
    @import '~@/style/crm.less';
    // .zidongshifang {
    //     .ant-select-selection__rendered,
    //     .ant-select-selection-selected-value,
    //     .ant-select-selection {
    //         height: 28px;
    //         line-height: 28px;
    //     }
    // }
</style>
